<template>
  <div>
      <van-nav-bar
    title="我的收藏"
    left-text="返回"
    left-arrow
    @click-left="$router.go(-1)"
  />
  <div v-for="item in items" :key="item.dishId" class="text" >
      <div class="re-left">
        <img :src=item.dishPicture alt="">
      </div>
      <div class="re-right">
        <strong>{{ item.dishName }}</strong> <br>
        <span>{{ item.dishDescription }}</span><br>
        <span class="amount">已售{{ item.dishSold }}+</span> <br>
        <p>￥{{ item.dishPrice }}</p>
        <button @click="shanchu(item)">删除</button>
      </div>
    </div>
  </div>
</template>

<script>
//获取收藏数据
import {getMyShoucang} from '@/api/user'
//删除收藏
import{changeShoucang} from '@/api/dish'
import { mapState} from "vuex";
export default {
 name:'ShouCang',
 data() {
  return {
    items: [],
    refreshFlag: true
  }
 },
 async created(){
    await getMyShoucang(this.userInfo.userId).then((res)=>{
      this.items=res.data.dishList
      if(this.items==''){
        this.$toast('您未收藏过菜品')
      }
      console.log('数据',res.data.dishList);
    })
 },
 computed: {
    //获取存储数据
  ...mapState('user',["userInfo"])
},
 methods:{
  //修改状态
  shanchu(item){
    item.dishIsshoucang = 0
    changeShoucang(item.dishIsshoucang,this.userInfo.userId
,parseInt(item.dishId) ).then(() => {
  this.$toast('删除成功')
  location.reload(); 
      // this.refreshFlag = !this.refreshFlag;
      // console.log(res);
    });
  }
 }
}
</script>

<style lang="less" scoped>

.text{
      display: flex;
      flex-direction: row;
      margin-top: 10px;
      .re-left{
      img{
        border-radius: 10px;
         width: 150px;
        height: 83%;
        margin-top: 10px;
        margin-left: 10px;
        margin-right: 5px;
      }
     
  }
  .re-right{
    margin-left: 15px;
    strong{
      font-size: 15px;
    }
      span{
          word-break:break-all;  
          display: inline-block;
          width: 180px;
          color: #a4a3a3;
          margin-top: 7px;
      }
      p{
          font-weight: 700;
          margin-top: 65px;
          font-size: 17px;
          display: inline-block;
          width: 100px;
          color: red;
      }
      .amount{
         position: relative;
         top: 35%; 
      }
      button{
        margin-left: 120px;
        position: relative;
        top: -10%;
        color: aliceblue;
        background-color: red;
        border: 0;
        width: 35px;
        height: 20px;
        border-radius: 10px;
        font-size: 10px;
      }
  }
  }

</style>